const Actions = require('./actions');
const DB = require('app/db.js');
import { monStorage, Storage } from 'clientConfig/util/StoreData';
import { Control } from 'react-keeper';
const { Toast } = SaltUI
import { NEW, RUNNING, TERMINATED, COMPLETED, CANCELED } from 'clientConfig/constants'
import { getTime, getMarkdownText, sendNotice, mergeArray } from 'clientConfig/util/queryurlfield';
//合同签订完成的消息机器人地址通知
const hook = 'https://oapi.dingtalk.com/robot/send?access_token=dc99997194e3c037029fdb883a512b5bd4ba7051eafee5c18853b256ffc5a010';
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {

    },
    onFetch: function (params, cb) {
        let t = this;
        var updataContent = {};//表单修改的字段
        let updataContent1 = {};
        let cc_list = Control.state.cc_list;
        let folder_id = Control.state.folder_id;//文件夹id
        let process_id = Control.state.process_id;
        let form_component_values = Control.state.form_component_values//内容变更的表单数据
        var file_id = [];
        var selected_folder_id = [];
        if (form_component_values.nodelists.length == 1) {

            let node_info = form_component_values.nodelists[0].node_info;
            for (let item of node_info) {
                if (item.name == "上传附件" || item.name == "上传图片") {
                    let data = JSON.parse(item.value);
                    for (let subitem of data) {
                        file_id.push(subitem.fileId);
                        selected_folder_id.push(subitem.selected_folder_Id);
                    }
                }
            }
            // if (form_component_values.nodelists[0].node_name == "faultreq") {
            // } 
        } else {
            if (JSON.parse(form_component_values.content.attach_info).length > 0) {
                let data = JSON.parse(form_component_values.content.attach_info);
                for (let subitem of data) {
                    file_id.push(subitem.fileId);
                    selected_folder_id.push(subitem.selected_folder_Id);
                }
            }
        }
        let payplanId = Control.state.payplanId;
        let origin = Control.state.origin;
        let finish_time = Control.state.finish_time;
        let process_result = Control.state.process_result;
        let approval_type = Control.state.proj_type.includes('-') ? Control.state.proj_type.split('-')[1] : Control.state.proj_type;//software
        let $approval_type = Control.state.proj_type.includes('-') ? Control.state.proj_type.split('-')[0] : "";//是否为审批单变更
        let originator_user = Control.state.sender;
        let proj_name = Control.state.proj_name;
        let proj_num = Control.state.proj_num;
        let paypointerNum = Control.state.paypointerNum; //支付计划节点数
        let payPointerCurrNum = Control.state.payPointerCurrNum; //当前的支付节点
        let next_cursor = parseInt(Control.state.next_cursor); //审批单的游标状态
        let approvers = Control.state.approvers instanceof Array ? Control.state.approvers : [Control.state.approvers]; //审批人列表
        let approvers_id = Control.state.approvers_id instanceof Array ? Control.state.approvers_id : (Control.state.approvers_id ? [Control.state.approvers_id] : []); //审批人的id
        let cc_list_id = Control.state.cc_list_id instanceof Array ? Control.state.cc_list_id : (Control.state.cc_list_id ? [Control.state.cc_list_id] : []); //抄送人的idxs
        let originator_user_id = Control.state.originator_user_id;//发送人用户id
        let toApprovers = [];
        // debugger
        if (approvers.length == 1) {
            updataContent.finish_time = getTime();
            let obj = null;
            try {
                obj = JSON.parse(process_result)
            } catch (e) {
                obj = process_result
            }
            if (params.content)
                obj.content = params.content;
            if (params.file)
                obj.file = params.file;
            if (params.image)
                obj.image = params.image;
            updataContent.process_result = JSON.stringify(obj);
        } else {
            if (finish_time != "") {
                if (!(finish_time instanceof Array)) {
                    let array = [];
                    array.push(finish_time); //审批创建时间出现两个
                    array.push(getTime());
                    finish_time = array;
                } else {
                    finish_time[next_cursor] = getTime();
                }
            } else {
                finish_time = getTime();
            }
            updataContent.finish_time = finish_time;
            let obj = null;
            try {
                if (process_result instanceof Array) {
                    let p = JSON.parse(process_result[next_cursor]);
                    if (p instanceof Array) obj = p
                    else obj = p
                } else {
                    let p = JSON.parse(process_result);
                    if (p instanceof Array) obj = p[next_cursor]
                    else obj = p
                }
            } catch (e) {
                obj = process_result[next_cursor];
            }
            if (!obj)
                obj = { content: "", file: "", imgae: "" };
            if (params.content)
                obj.content = params.content;
            if (params.file)
                obj.file = params.file;
            if (params.image)
                obj.imgae = params.image;
            if (process_result instanceof Array) {
                process_result[next_cursor] = JSON.stringify(obj)
            } else {
                process_result = JSON.stringify(obj)
            }
            updataContent.process_result = process_result;
        }
        if (params.suggestType == '同意') {
            next_cursor++
            if (approval_type == 'payreq' && $approval_type == '') {
                updataContent1 = form_component_values.content;
                updataContent1.finish_time = !updataContent1.finish_time ? [] : updataContent1.finish_time instanceof Array ? updataContent1.finish_time : []
                if (paypointerNum == 1) {
                    if (next_cursor < approvers.length) {
                        updataContent.next_cursor = next_cursor;//支付申请的审批单的状态修改
                        updataContent1.payPoniterStatus = '同意支付';//支付计划的审批单的修改
                        updataContent.status = RUNNING
                    } else if (next_cursor == approvers.length) {
                        updataContent1.paypointerStrack = 100;//支付计划的审批单的修改
                        updataContent1.payPoniterStatus = '支付完成';//支付计划的审批单的修改
                        updataContent.status = COMPLETED; //支付申请的审批单的状态修改
                    }
                    updataContent1.finish_time.push(getTime())
                    updataContent1.finish_time.push(getTime())
                } else if (paypointerNum == 2) {
                    if (payPointerCurrNum == 0) {
                        if (next_cursor < approvers.length) {
                            updataContent.next_cursor = next_cursor;
                            updataContent.status = RUNNING
                        } else if (next_cursor == approvers.length) {
                            updataContent1.payPointerCurrNum = parseInt(payPointerCurrNum) + 1
                            updataContent1.payPoniterStatus = '同意支付';//支付计划的审批单的修改
                            updataContent1.paypointerStrack = 50;//支付计划的审批单的修改
                            updataContent.status = COMPLETED;
                        }
                    } else if (payPointerCurrNum == 1) {
                        if (next_cursor < approvers.length) {
                            updataContent.next_cursor = next_cursor;
                            updataContent.status = RUNNING
                        } else if (next_cursor == approvers.length) {
                            updataContent1.payPointerCurrNum = parseInt(payPointerCurrNum) + 1
                            updataContent1.payPoniterStatus = '支付完成';//支付计划的审批单的修改
                            updataContent1.paypointerStrack = 100;//支付计划的审批单的修改
                            updataContent.status = COMPLETED;
                        }
                    }
                    updataContent1.finish_time.push(getTime())
                }
            } else {
                if (next_cursor < approvers.length) {
                    updataContent.next_cursor = next_cursor;
                    updataContent.status = RUNNING
                } else if (next_cursor == approvers.length) {
                    updataContent.status = COMPLETED;
                }
                //立项审批逻辑
                if (approval_type == 'software') {
                    if (form_component_values.nodelists[0].node_name == "合同签订时间" && next_cursor == 1) {
                        form_component_values.nodelists[0].node_state = 2;
                    }
                    updataContent.form_component_values = form_component_values;
                }
                for (let i = next_cursor; i < approvers.length; i++) {
                    toApprovers.push(approvers[i].ender);
                }
            }
        } else if (params.suggestType == '拒绝') {
            updataContent.status = TERMINATED;
            let array = [],
                array_id = [];

            for (let i = 0; i < approvers.length; i++) {
                array.push(approvers[i].ender);
                array_id.push(approvers_id[i]);
            }
            updataContent.approvers = array
            updataContent.approvers_id = array_id
            ++next_cursor
        } else if (params.suggestType == '评论') {
            //新增一个节点
            if (updataContent.process_result instanceof Array) {
                // updataContent.process_result[next_cursor] = JSON.stringify(updataContent.process_result)
                updataContent.process_result.splice(next_cursor + 1, 0, JSON.stringify({ content: "", file: "", imgae: "" }));
            } else {
                let array = [];
                array.push(updataContent.process_result);
                array.push(JSON.stringify({ content: "", file: "", imgae: "" }));
                updataContent.process_result = array;
            }
            if (updataContent.finish_time instanceof Array) {
                updataContent.finish_time.splice(next_cursor, 0, getTime());
            } else {
                let array = [];
                if (finish_time != '') {
                    array.push(finish_time);
                    array.push(getTime());
                } else {
                    array.push(getTime());
                }
                updataContent.finish_time = array;
            }
            let array = [],
                array_id = [];

            for (let i = 0; i < approvers.length; i++) {
                array.push(approvers[i].ender);
                array_id.push(approvers_id[i]);
            }
            array.splice(next_cursor, 0, array[next_cursor]);
            array_id.splice(next_cursor, 0, array_id[next_cursor]);
            updataContent.approvers = array;
            updataContent.approvers_id = array_id;
            updataContent.next_cursor = ++next_cursor;
            updataContent.status = RUNNING;
        }
        let proj_markdown = null;
        let title = '';
        switch (approval_type) {
            case 'software':
                title = '计划管理';
                break;
            case 'sourcecode':
                title = '成果管理';
                break;
            case 'payplan':
                title = '支付计划';
                break;
            case 'payreq':
                title = '支付申请';
                break;
            case 'paystatistics':
                title = '支付流转';
                break;
            case 'faultreq':
                title = '维护申请';
                break;
            case 'faulthandle':
                title = '维护处理';
                break;
            case 'falutarrange':
                title = '维护安排';
                break;
            case 'falutfeedback':
                title = '维护反馈';
                break;
            case 'tenderplan':
                title = '招标计划';
                break;
            case 'tenderprocure':
                title = '采购方式';
                break;
            case 'tenderpurchase':
                title = '采购结果';
                break;
            case 'tendercontractsign':
                title = '合同签订';
                break;
        }
        let $finish_time = updataContent.finish_time instanceof Array ? updataContent.finish_time[next_cursor - 1] : updataContent.finish_time
        if (updataContent.process_result instanceof Array) {
            proj_markdown = getMarkdownText({ create_time: $finish_time, originator_user, approvers: approvers[next_cursor - 1].ender, toApprovers, proj_name, proj_num, status: updataContent.status, process_result: JSON.parse(updataContent.process_result[next_cursor - 1]).content, title }, "update")
        } else {
            proj_markdown = getMarkdownText({ create_time: $finish_time, originator_user, approvers: approvers[next_cursor - 1].ender, toApprovers, proj_name, proj_num, status: updataContent.status, process_result: JSON.parse(updataContent.process_result).content, title }, "update")
        }
        updataContent.proj_markdown = proj_markdown;
        DB.Approval.update_approval.config.query = { process_id: process_id, robot: (!!title == '支付申请') }
        console.log(approvers)
        //合同签订完成的通知
        if (approval_type == 'contractsign' && next_cursor == approvers.length && params.suggestType == '同意') {
            // if (updataContent.process_result instanceof Array) {
            //     proj_markdown = getMarkdownText({ create_time: updataContent.finish_time, originator_user, approvers: approvers[next_cursor].ender, proj_name, proj_num, status: updataContent.status, process_result: JSON.parse(updataContent.process_result[next_cursor]).content,title:'合同签订' }, "update")
            // } else {
            //     proj_markdown = getMarkdownText({ create_time: updataContent.finish_time, originator_user, approvers: approvers[next_cursor].ender, proj_name, proj_num, status: updataContent.status, process_result: JSON.parse(updataContent.process_result).content,title:'合同签订' }, "update")
            // }
            updataContent.proj_webhook = hook;
        }
        // debugger
        DB.Approval.update_approval(updataContent).then((content) => {// 成功
            Toast.show({
                type: "success",
                content: params.suggestType == '评论' ? '评论完成' : '审批完成',
            })
            Control.go(-2);
            // debugger
            //消息的逻辑
            if (params.suggestType != '评论') {
                if (next_cursor < approvers.length) {
                    if (params.suggestType == '同意') {
                        this.send_notice({ process_id, proj_name, proj_num, status: updataContent.status, create_time: updataContent.finish_time }, { mes_receiver: approvers_id[next_cursor], islast: false });
                    } else if (params.suggestType == '拒绝') {
                        this.send_notice({ process_id, proj_name, proj_num, status: updataContent.status, create_time: updataContent.finish_time }, { mes_receiver: originator_user_id, islast: true });
                    }
                } else {
                    if (params.suggestType == '同意') {
                        this.send_notice({ process_id, proj_name, proj_num, status: updataContent.status, create_time: updataContent.finish_time }, { mes_receiver: originator_user_id, islast: true }, cc_list_id);
                    } else if (params.suggestType == '拒绝') {
                        this.send_notice({ process_id, proj_name, proj_num, status: updataContent.status, create_time: updataContent.finish_time }, { mes_receiver: originator_user_id, islast: true });
                    }
                }
            }
            // debugger
            //变更申请
            if ($approval_type == 'changereq') {
                if (params.suggestType == '同意' && next_cursor == approvers.length) {
                    let process_id = JSON.parse(form_component_values.content.changerecord_type).old_process_id
                    DB.Approval.get_approval_detail({ process_id: process_id }).then((content) => {
                        this.updateApproval(form_component_values, content, { proj_name });
                    })
                }
            }

            //绑定项目参与者
            if (params.suggestType == '同意') {
                // debugger
                if (next_cursor == approvers.length) {
                    this.bindParticipant(approval_type, proj_name, approvers_id, originator_user_id, cc_list_id);
                    //创建文件根目录
                    if (approval_type == 'software' || approval_type == 'tenderplan') {
                        this.createProjFile(process_id, file_id, approval_type);
                    }
                }
            }
            //绑定文件权限参与者
            if (params.suggestType == '同意') {
                //  debugger
                if (next_cursor == approvers.length) {
                    if (file_id instanceof Array && selected_folder_id instanceof Array) {
                        for (let key in file_id) {
                            this.bindFilePermission(file_id[key], approvers_id, originator_user_id, cc_list_id);
                        }
                    } else {
                        this.bindFilePermission(file_id, approvers_id, originator_user_id, cc_list_id);
                    }
                }
            }
            //修改文件存储区域
            if (params.suggestType == '同意' && next_cursor == approvers.length) {
                if (file_id instanceof Array && selected_folder_id instanceof Array) {
                    for (let key in file_id) {
                        this.updateFileInfo({ file_id: file_id[key], folder_id: selected_folder_id[key] });
                    }
                } else {
                    this.updateFileInfo({ file_id, folder_id: selected_folder_id });
                }
            }
            t.data.loading = false;
            t.updateComponent();
        })
            .then(() => {
                //成果审批单逻辑更改立项表单
                if (approval_type == 'sourcecode' || approval_type == 'tenderachievement') {
                    // debugger
                    // console.log(form_component_values)
                    let text = "";
                    if (approval_type == 'sourcecode') {
                        text = "所属节点";
                    } else if (approval_type == 'tenderachievement') {
                        text = "所属招标节点";
                    }
                    let pre_process_id = form_component_values.content.process_id;
                    for (let i = 0; i < form_component_values.nodelists.length; i++) {
                        for (let j = 0; j < form_component_values.nodelists[i].node_info.length; j++) {
                            if (form_component_values.nodelists[i].node_info[j].name == text) {
                                var point = form_component_values.nodelists[i].node_info[j].value;
                                break;
                            }
                        }
                    }
                    //  debugger
                    DB.Approval.get_approval_detail({ process_id: pre_process_id }).then((content) => {
                        let nodelists = content.form_component_values.nodelists;
                        //  debugger
                        for (let item of nodelists) {
                            let has = false;//是否超时，3次未通过超时
                            if (item.node_name.includes("／")) {
                                item.node_name = item.node_name.replace(/\／/g, '/');
                            }
                            if (item.node_name.includes(point)) {
                                if (params.suggestType == '同意') {
                                    item.node_state = 2;
                                }
                                let subitem = '';
                                //  debugger
                                for (let key in item.node_achievements) {
                                    subitem = item.node_achievements[key];
                                    if (subitem.status != 1) {
                                        has = true;
                                    }
                                    if (subitem.process_id == process_id) {
                                        if (params.suggestType == '同意') {
                                            subitem.status = 2;
                                        } else if (params.suggestType == '拒绝') {
                                            subitem.status = 1;
                                            if (!has && key > 1) {
                                                subitem.status = 0;
                                                item.node_state = 0;
                                            }
                                        }
                                    }
                                }
                                if (item.node_state != 0) {
                                    let end_time = new Date(item.node_info[item.node_info.length - 1].value + ' 23:59:59').getTime();
                                    if (Date.now() > end_time) {
                                        item.node_state = 0;
                                    }
                                }
                                break;
                            }
                        }
                        let updataContent = {
                            "form_component_values": {
                                nodelists
                            }
                        }
                        // debugger
                        return { process_id: pre_process_id, updataContent }
                    })
                        .then(({ updataContent, process_id }) => {
                            DB.Approval.update_approval.config.query = { process_id, robot: 1 };
                            DB.Approval.update_approval(updataContent).then((content) => {// 成功
                            })
                        })
                }
            })
            .catch((error) => { // 失败 or 有异常被捕获
                console.log(error.errmsg)
            });
        if (approval_type == 'payreq' && params.suggestType == '同意' && JSON.stringify(updataContent1) != "{}") {
            DB.Approval.update_approval.config.query = { process_id: payplanId, robot: 1 }
            DB.Approval.update_approval({
                "form_component_values": {
                    "content": updataContent1
                }
                //updataContent1:JSON.stringify(updataContent1)
            }).then((content) => {// 成功

            }).catch((error) => { // 失败 or 有异常被捕获

            });
        }
    },
    updateComponent: function () {
        this.trigger(this.data);
    },
    //变更申请的逻辑
    updateApproval: function (form_component_values, content, params = undefined) {
        let newfinishTime = content.finish_time
        let newApprovals = content.approvers
        let newprocess_result = content.process_result
        let newnext_cursor = content.next_cursor
        let changerecord_type = JSON.parse(form_component_values.content.changerecord_type).type;
        if (changerecord_type == "撤销申请") {
            let proj_category = JSON.parse(form_component_values.content.changerecord_type).old_proj_category;
            if (content.status == 1) {//若在审批前撤销，撤销人为自己
                newApprovals = monStorage.get('user.nickname');
                newnext_cursor = 0;
                newprocess_result = JSON.stringify({ content: "", file: "", imgae: "" })
                Toast.show({
                    type: "success",
                    content: '流程全部结束'
                })
            }
            if (newfinishTime instanceof Array) {
                newfinishTime[newfinishTime.length - 1] = getTime()
            } else {
                if (content.approvers instanceof Array && content.status == 2) {//若在审批中撤销，去除审批人数组中大于等于当前游标的人
                    newApprovals.splice(content.next_cursor, 1);
                    newprocess_result.splice(content.next_cursor, 1);
                    if (newApprovals.length == 1) {
                        newApprovals = newApprovals[0];
                        newnext_cursor = 0;
                        newprocess_result = JSON.stringify({ content: "", file: "", imgae: "" })
                    }
                }
                newfinishTime = getTime()
            }
            var updataContent = {
                "status": CANCELED,
                "proj_category": "changereq",
                "approvers": newApprovals,
                "finish_time": newfinishTime,
                "next_cursor": newnext_cursor,
                "process_result": newprocess_result,
                "form_component_values": {
                    "content": {
                        "changerecord_type": JSON.stringify({ old_type: proj_category })
                    }
                }
            }
        } else {
            var node_lists = form_component_values.nodelists;
            for (let i = 0; i < node_lists.length; i++) {
                let node_info = node_lists[i].node_info;
                for (let j = 0; j < node_info.length; j++) {
                    if (node_info[j].ext_value) {
                        node_info[j].ext_value = "";
                        if (node_lists[i].permission == 1) {
                            let n = parseInt(node_lists[i].modified);
                            ++n;
                            node_lists[i].modified = `${n}`;
                        }
                    }
                }
                node_lists[i].node_info = node_info;
            }
            var updataContent = {
                "form_component_values": { "nodelists": node_lists }
            }
        }
        console.log(updataContent)

        let old_process_id = JSON.parse(form_component_values.content.changerecord_type).old_process_id
        DB.Approval.update_approval.config.query = { process_id: old_process_id, robot: 1 }
        DB.Approval.update_approval(updataContent).then((content) => {// 成功
            if (changerecord_type == "撤销申请") {
                this.deleteProjFile(old_process_id, folder_id);
                if (proj_category == 'software' || proj_category == 'tenderplan') {
                    this.unbindParticipant({ proj_name: params.proj_name, proj_category });
                }
            }
        }).catch((error) => { // 失败 or 有异常被捕获

        });
    },
    //消息发送的逻辑
    send_notice: function (required_params, noticed_lists, cc_list_id = undefined) {
        let notice_info = {
            "process_id": required_params.process_id,
            "proj_num": required_params.proj_num,
            "proj_name": required_params.proj_name,
            "create_time": required_params.create_time,
            "status": required_params.status,
            "type": noticed_lists.islast ? "我发起的" : "待审批的"
        }
        // debugger
        sendNotice(noticed_lists.mes_receiver, notice_info);
        if (cc_list_id) {
            notice_info.type = "抄送我的";
            sendNotice(cc_list_id, notice_info);
        }
    },
    //绑定参与者的逻辑
    bindParticipant: function (approval_type, proj_name, unionids, originator_user_id, cc_list_id = undefined) {
        // debugger
        if (approval_type == 'software') {
            var text = 1;
        } else if (approval_type == 'tenderplan') {
            var text = 2;
        }
        unionids.push(originator_user_id);
        const set = new Set(unionids);
        let data = Storage.get("partici-" + proj_name);
        let num = 0;
        // debugger
        if (!data) {
            data = set;
        } else {
            if (!(data instanceof Set)) {
                data = new Set(data);
                num = data.size;
            }
            unionids.forEach(element => {
                data.add(element)
            });
        }
        if (cc_list_id) {
            if (cc_list_id instanceof Array) {
                if (cc_list_id.length > 0)
                    cc_list_id.forEach(item => data.add(item));
            } else {
                data.add(cc_list_id)
            }
        }
        if (data.size == num) return;

        let participant = [...data]
        console.log(participant);
        // debugger
        Storage.set("partici-" + proj_name + text, data);
        DB.Permission.bind_participant({ pro_name: proj_name, participant: JSON.stringify(participant) })
            .then((content) => {

            })
            .catch((error) => {
                Toast.show({
                    type: "error",
                    content: "绑定项目参与者未成功"
                })
            });
    },
    //删除绑定参与者的逻辑
    unbindParticipant: function ({ proj_name, proj_category }) {
        if (proj_category == 'software') {
            var text = 1;
        } else if (proj_category == 'tenderplan') {
            var text = 2;
        }
        if (proj_name) {
            let data = Storage.get("partici-" + proj_name + text);
            let participant = [...data]
            DB.Permission.unbind_participant({ pro_name: proj_name, participant: JSON.stringify(participant) })
                .then((content) => {

                })
                .catch((error) => {
                    console.log(error);
                });
        }
    },
    //创建文件根路径
    createProjFile: function (process_id, file_id, approval_type) {
        DB.File.create_file_path({
            process_id: process_id,
            parent_folder_id: '',
            file_uper: Storage.get('user.id')
        }).then((content) => {
            let name = '';
            if (approval_type == 'software') {
                name = '实施';
            } else if (approval_type == 'tenderplan') {
                name = '招标';
            }
            for (let item of content.sub) {
                if (item.folder_name == name) {
                    let folder_id = item.folder_id;
                    this.updateFileInfo({ file_id, folder_id });
                    break;
                }
            }
        })
    },
    //修改文件夹信息
    updateFileInfo: function ({ file_id, folder_id }) {
        if (file_id && folder_id) {
            DB.File.update_file_info({
                file_id,
                folder_id,
                // id: Storage.get('user.id')
            })
                .then((content) => {
                    // debugger
                })
                .catch((error) => {

                });
        }
    },
    //删除文件根路径
    deleteProjFile: function (process_id, folder_id) {
        DB.File.delete_file_path({
            process_id: process_id,
            folder_id: folder_id,
            file_uper: Storage.get('user.id')
        }).then((content) => {

        })
    },
    //绑定文件参与者的逻辑
    bindFilePermission: function (file_id, unionids, originator_user_id, cc_list_id = undefined) {
        // debugger
        unionids.push(originator_user_id);
        const set = new Set(unionids);
        let data = set;
        if (cc_list_id) {
            if (cc_list_id instanceof Array) {
                if (cc_list_id.length > 0)
                    cc_list_id.forEach(item => data.add(item));
            } else {
                data.add(cc_list_id)
            }
        }
        let participant = [...data];
        // debugger
        if (file_id) {
            DB.Permission.bind_file_permission({ file_id, participant: JSON.stringify(participant) })
                .then((content) => {

                })
                .catch((error) => {
                    Toast.show({
                        type: "error",
                        content: "绑定文件参与者未成功"
                    })
                });
        }
    },
    //删除文件参与者的逻辑
    unbindFilePermission: function ({ file_id, participant }) {
        if (file_id) {
            DB.Permission.unbind_file_permission({ file_id, participant: JSON.stringify(participant) })
                .then((content) => {

                })
                .catch((error) => {
                    console.log(error);
                });
        }
    }
});
